package com.kele.syn;



/**
 * @author kele
 * @date 2021/10/9 16:02
 * @description 传统的synchronized
 */
public class SaleTicket {



    public static void main(String[] args) {
        Ticket ticket=new Ticket();
        new Thread(()->{
            ticket.sale();

        },"A").start();

        new Thread(()->{
            ticket.sale();
        },"B").start();
    }


}

class Ticket{
    public int num=20;
    public synchronized void sale(){
            while (num>0){
                num--;
                System.out.println(Thread.currentThread().getName()+" :正卖票 "+num+"剩余"+num );
            }


    }
}
